<template>
  <sub-page>
    <q-toolbar-title slot="title">查看用户信息</q-toolbar-title>

    <q-page slot="content">
      <div>{{ account.nickName }}</div>
      <div><q-btn icon="add" label="加好友" @click="addFriend"></q-btn></div>
      <ul>
        <li v-for="(item, index) in entityList" :key="index">
          {{ item.name }}
        </li>
      </ul>
    </q-page>
  </sub-page>
</template>

<script>
import SubPage from "@/components/SubPage.vue";
import Entity from "@/js/business/entity.js";

export default {
  components: { SubPage },
  data() {
    return {
      account: null,
      entityList: [],
      entityService: new Entity(),
    };
  },
  methods: {
    async addFriend() {
      try {
        this.$account.addFriend(this.account.account_id);
      } catch (err) {
        console.log(err);
      }
    },
  },
  mounted: async function () {
    try {
      let acc_id = this.$route.params.account_id;
      let resAccPromise = this.$account.getAccount(acc_id);
      let resEntPromise = this.entityService.getByUser(acc_id);
      let resAcc = await resAccPromise;
      let resEnt = await resEntPromise;
      this.account = resAcc.data;
      this.entityList = resEnt.data;
    } catch (err) {
      console.log(err);
    }
  },
};
</script>